Skip to content

Implement pending purchase handling for Unity IAP and update README#112

Open
sotash wants to merge 4 commits into
mainfrom
feature/unity-purchasing-implementation
Open

Implement pending purchase handling for Unity IAP and update README#112
sotash wants to merge 4 commits into
mainfrom
feature/unity-purchasing-implementation

Conversation

@sotash
Copy link
Copy Markdown
Contributor

@sotash sotash commented May 22, 2026

Summary

This PR ensures proper purchase processing when using Unity IAP by implementing pending purchase handling. It also refactors and updates the README documentation for better troubleshooting guidance.

Changes

  • Unity IAP Handling: Updated OnPurchasePending to call GameDataController.UnlockInGameContent and StoreController.ConfirmPurchase to handle pending transactions correctly.
  • Documentation (README.md):
    • Renamed the Support section to Troubleshooting and added a new relevant item.
    • Made minor content adjustments to align with recent Unity version upgrades.

Verifications

  • Confirmed that pending purchases trigger content unlocking and purchase confirmation sequentially.
  • Reviewed README changes for clarity and formatting.

sotash added 3 commits May 21, 2026 13:38
Update README.md
Add UnlockInGameContent and ConfirmPurchase calls on OnPurchasePending to properly acknowledge purchases
Update README.md
@sotash sotash self-assigned this May 22, 2026
Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request updates the project to Unity 6.3 LTS and Unity IAP 5.3.0, alongside documentation improvements and updated troubleshooting steps in the README. A critical security and logic issue was identified in PurchaseController.cs, where in-game content is unlocked and purchases are confirmed during the 'Pending' state instead of the 'Confirmed' state, potentially allowing access to items before payment is finalized. Additionally, a null check for obj.CartOrdered is recommended to prevent a potential NullReferenceException.

Comment on lines +157 to +161
foreach (var product in obj.CartOrdered.Items())
{
GameDataController.UnlockInGameContent(product.Product.definition.id);
}
_storeController.ConfirmPurchase(obj);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

Unlocking content and confirming the purchase within the OnPurchasePending handler is a security and logic risk. A "Pending" state in IAP (such as Google Play's Pending Transactions or Apple's Ask to Buy) indicates that the transaction has been initiated but not yet completed. Granting access to content at this stage allows users to receive items before payment is finalized. This logic should be moved to the OnPurchaseConfirmed handler. Additionally, the code should check if obj.CartOrdered is null before iterating over its items to avoid a potential NullReferenceException.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This implementation is based on Unity's documentation. Also, implementation in this sample is just an example.
Added a null check.

Add a null check to PurchaseController.cs
@imut4503-oss
Copy link
Copy Markdown

Tg

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants